package com.demo.morning;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @ClassName Time练习
 * @Description TODO
 * @Author tianqinglong
 * @Date 11:27 2022/7/7
 * @Version 1.0
 **/
public class Time练习 {
    public static void main(String[] args) throws ParseException {
        测试();
        ceshi();
    }

    private static void ceshi() throws ParseException {
        String time="2000-01-01 00:00:00";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date parse = sdf.parse(time);
        Date date = new Date();
        long now=date.getTime();
        long time1 = parse.getTime();
        long days=(now-time1)/1000/(3600*24);
        System.out.println("2000-01-01过了"+days+"天");
    }

    private static void 测试() throws ParseException {
        System.out.println(1);
        Date date = new Date();
        System.out.println(date);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println(sdf.format(date));
        String time="2022-07-07 12:12:12";
        Date parse = sdf.parse(time);
        System.out.println(parse);
    }
}
